package com.ruoyi.platform.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.platform.domain.TbApp;
import com.ruoyi.platform.service.ITbAppService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 应用优化Controller
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/app")
public class TbAppController extends BaseController
{
    @Autowired
    private ITbAppService tbAppService;

    /**
     * 查询应用优化列表
     */
    //@RequiresPermissions("platform:app:list")
    @GetMapping("/list")
    public TableDataInfo list(TbApp tbApp)
    {
        startPage();
        List<TbApp> list = tbAppService.selectTbAppList(tbApp);
        return getDataTable(list);
    }

    /**
     * 导出应用优化列表
     */
    //@RequiresPermissions("platform:app:export")
    @Log(title = "应用优化", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbApp tbApp)
    {
        List<TbApp> list = tbAppService.selectTbAppList(tbApp);
        ExcelUtil<TbApp> util = new ExcelUtil<TbApp>(TbApp.class);
        util.exportExcel(response, list, "应用优化数据");
    }

    /**
     * 获取应用优化详细信息
     */
    //@RequiresPermissions("platform:app:query")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return success(tbAppService.selectTbAppByAppId(appId));
    }

    /**
     * 新增应用优化
     */
    //@RequiresPermissions("platform:app:add")
    @Log(title = "应用优化", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbApp tbApp)
    {
        return toAjax(tbAppService.insertTbApp(tbApp));
    }

    /**
     * 修改应用优化
     */
    //@RequiresPermissions("platform:app:edit")
    @Log(title = "应用优化", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbApp tbApp)
    {
        return toAjax(tbAppService.updateTbApp(tbApp));
    }

    /**
     * 删除应用优化
     */
    //@RequiresPermissions("platform:app:remove")
    @Log(title = "应用优化", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds)
    {
        return toAjax(tbAppService.deleteTbAppByAppIds(appIds));
    }
}
